package com.emperor.service.impl;

import com.emperor.mapper.EquipmentMapper;
import com.emperor.service.EquipmentService;
import com.emperor.vo.RegionDataVo;
import com.emperor.vo.SkuClassPageVo;
import com.emperor.vo.VendingMachineVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentMapper equipmentMapper;

    @Override
    public SkuClassPageVo findAll(Integer pageIndex, Integer pageSize, String name) {
        PageHelper.startPage(pageIndex, pageSize);
        List<VendingMachineVo> list = equipmentMapper.findAll(name);
        Page<VendingMachineVo> p = (Page<VendingMachineVo>) list;
        // 计算总页数
        long l = (p.getTotal() / pageSize) + 1;
        // 创建SkuClassPageVo对象
        SkuClassPageVo build = SkuClassPageVo.builder().
                pageIndex(pageIndex).
                pageSize(pageSize)
                .totalPage((int) l).totalCount((int) p.getTotal())
                .currentPageRecords(new List[]{p.getResult()}).build();
        // 返回SkuClassPageVo对象
        return build;
    }
}
